package day10.threadLocal.example;

import java.util.concurrent.TimeUnit;

/**
 * <>
 * <详细描述>
 *
 * @Author WANG.SONG.
 * @Date 2019/3/13 0013 23:31
 * @see
 */
public class Test {
    public static void execute(String dbNo, int fetchCount) {
        Long startTime = System.currentTimeMillis();
        // 打点供后续子流程使用统一的关联ID
        ThreadMsgHoldContext.put();
        // 初始化应用系统监控
        try {
            System.out.println(ThreadMsgHoldContext.get());
        } catch (RuntimeException e) {
            throw new RuntimeException(  " error, dbNo=" + dbNo + ",fetchCount=" + fetchCount, e);
        } finally {
            ThreadMsgHoldContext.remove();
        }
    }

    public static void main(String[] args) {

        new SimpleThreadPool().doTask(new Runnable() {
            @Override
            public void run() {
                ThreadMsgHoldContext.put();
                System.out.println(Thread.currentThread().getName()+":"+ThreadMsgHoldContext.get());
            }
        });

        new SimpleThreadPool().doTask(new Runnable() {
            @Override
            public void run() {

                ThreadMsgHoldContext.put();
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+":"+ThreadMsgHoldContext.get());
            }
        });

    }
}
